#pragma once
#include "MeshDeform/Database.h"
#include "NIBase.h"
#include "cv.h"
#include "NIJointManager.h"

class NIOperate : public NIBase
{
public:
	NIOperate();
	~NIOperate(); 
	
	//Get member value
	inline bool	IsTracking(){ return m_IsTracking; }
	inline cv::Mat	GetImage(){ return m_cBGRImg; }
	inline XnPoint3D	GetJoints2D(const int index){ return m_Joints_2D[index]; }
	inline XnPoint3D	GetJoints3D(const int index){ return m_Joints_3D[index]; }
	inline XnPoint3D	GetSkeletonPos(XnSkeletonJoint eJointName);
	inline int	GetPrevJointNum(const int index){ return m_PrevJoint[index]; }
private:
	//Initialize content
	bool		InitContent();
	//Update content
	void		UpdateContent();
	inline void	UpdateSkeleton();
	inline void	UpdateUsers();
private:
	xn::SkeletonCapability	m_SC;
	XnUserID			m_UserID;
	XnCallbackHandle		m_hUserCB;
	XnCallbackHandle		m_hCalibCB;
	XnPoint3D		m_Joints_3D[15];
	XnPoint3D		m_Joints_2D[15];
	//cv
	cv::Mat			m_cBGRImg;
	cv::Mat			m_c8BitDepth;//not used

	bool			m_IsTracking;
	int			m_PrevJoint[15];

	NIJointManager		m_JointManager;

	
public:
	std::vector<RotateParam>  m_RotateParms;
	static const XnPoint3D	ZeroXnPoint3D;

	static inline bool IsEqualXnPoint3D(const XnPoint3D& a,const XnPoint3D& b);
	static inline bool IsZeroXnPoint3D(const XnPoint3D& a);
	static inline bool IsEqual_X(const XnPoint3D& a,const XnPoint3D& b);
};